var _pInfo = {
	"type": null,
	"userInfo": null,
	"isShowPwdByStatus": function(o) {
		var _status = $(o).attr("data-status");
		if(_status == "0") {
			$(o).attr({
				"data-status": "1",
				"src": "../public/images/hide.png"
			});
			$(o).prev().attr("type", "text");
		} else {
			$(o).attr({
				"data-status": "0",
				"src": "../public/images/show.png"
			});
			$(o).prev().attr("type", "password");
		}
	},
	"doSendCodeByType": function() {
		var _data = {}
		var agopasswd = $("#agopasswd").val().trim();
		var newpasswd = $("#newpasswd").val().trim();
		var againpasswd = $("#againpasswd").val().trim();
		if(!isNull(_pInfo.userInfo.email)) {
			_pInfo.type = "email";
			_data["accountnumber"] = _pInfo.userInfo.email;
		}
		if(!isNull(_pInfo.userInfo.tel)) {
			_pInfo.type = "tel";
			_data["accountnumber"] = _pInfo.userInfo.tel;
		}
		if(_pInfo.type == null) {
			$.alert("非法操作", function() {
				window.location.href = "personal-data.html";
			});
			return;
		}
		if(isNull(agopasswd)) {
			$.toast("原登录密码不能为空", "text");
			return;
		}
		if(isNull(newpasswd)) {
			$.toast("新登录密码不能为空", "text");
			return;
		}
		if(isNull(againpasswd)) {
			$.toast("请再次输入新登录密码", "text");
			return;
		}
		if(agopasswd.length < 6 || newpasswd.length < 6 || againpasswd.length < 6) {
			$.toast("登录密码最少输入6位数", "text");
			return;
		}
		if(newpasswd != againpasswd) {
			$.toast("两次密码输入不一致", "text");
			return;
		}
		_data["agopasswd"] = agopasswd;
		var opts = {
			url: _url + "/money/user/upsendcode",
			type: "post",
			load: true,
			data: _data,
			success: function(rs) {
				if(isReqSucceed(rs)) {
					$("#send-code-box").html(template("send-code-box-tpl", {
						rs: _pInfo.userInfo,
						type: _pInfo.type
					}));
					$("#send-code-popup").popup();
				}
			}
		}
		AjaxRequest(opts);
	},
	"doEditLoginPwd": function() {
		var newpasswd = $("#newpasswd").val().trim();
		var code = $("#code").val().trim();
		if(isNull(code)) {
			$.toast("请输入验证码", "text");
			return;
		}
		if(code.length < 4) {
			$.toast("验证码长度必须为4位", "text");
			return;
		}
		var _data = {
			"userid": _pInfo.userInfo.id,
			"newpasswd": newpasswd,
			"code": code
		};
		var opts = {
			url: _url + "/money/user/uppasswd",
			type: "post",
			load: true,
			data: _data,
			success: function(rs) {
				if(isReqSucceed(rs)) {
					$.alert("修改登陆密码成功", function() {
						window.location.href = "personal-data.html";
					});
				}
			}
		}
		AjaxRequest(opts);
	},
	"splitTel": function(str) {
		return str.substr(str.length - 4);
	},
	"loadEvents": function() {
		var _this = this;
		_pInfo.userInfo = _user.getUserInfo();
		$(document).on("click", ".img-size01", function() {
			_this.isShowPwdByStatus(this);
		});
	},
	"load": function() {
		this.loadEvents();
	}
}
exposeGlobalMethods({
	"doEditLoginPwd": function() {
		_pInfo.doEditLoginPwd();
	},
	"isShowPwdByStatus": function(o) {
		_pInfo.isShowPwdByStatus(o);
	},
	"doSendCodeByType": function() {
		_pInfo.doSendCodeByType();
	}
});
$(function() {
	_pInfo.load();
});